const express = require('express')
const userdelete = express.Router();

const mysql = require('mysql') //mysql也是个插件
const db = mysql.createPool({
    host: "127.0.0.1", //数据库的IP地址
    user: "root", //登录数据库的账户
    password: "root", //登录数据库的密码
    database: "xiangmu" //指定要操作哪个数据库
});


//管理员删除指定用户的数据

userdelete.get('/userdelete', (req, res) => {
    var sql = "delete from user where userid=?" //数据库的删除语句
        //前端传过来对应的id
    db.query(sql, [req.query.id], (err, result) => {
        // console.log(result.affectedRows)
        if (result.affectedRows >= 1) { //如果删除成功则会输出
            console.log('删除成功')
        }
    });
})


module.exports = userdelete